import os

basic = os.path.dirname(os.path.abspath(__file__))
date = os.path.join(basic, 'data')
xianren = os.path.join(date, "xianren.txt")
f = open(xianren, encoding="utf8")
file = f.read()
print(file)
f.close()

f2 = open(xianren, "w", encoding="utf-8")
f2.write("口你急哇")
f2.close()

try:
    print(['1'][100])
    print({"name": "yuz"}['bala'])
except IndexError:
    print("index")
    # 1/0
except KeyError:
    print("key")


class Dlao:
    favor = 'pytho'

    def __init__(self, name):
        self.name = name

    def eat(self, food):
        print("类方法 eat" + food)

    def offer(self, money, food):
        print("{}{}offer".format(self.name, money))
        self.eat(food)
        # 在类里面调用 调用方法
        # Dlao.eat(food)  不建议，因为类方法是指向实例自己

    @classmethod
    def lang(cls):
        print(cls.favor)


dalao = Dlao("kela")
dalao.offer("40k", "辣条")

Dlao.lang()


# 编写一个类，实现加减乘除
class cal:
    def __init__(self, num1, num2):
        self.num1 = num1
        self.num2 = num2

    def add(self):
        return self.num1 + self.num2


ad = cal(1, 2)
print(ad.add())


# 手机类，通话时 实现是否录音功能
class phone:
    def call(self, isrecord):
        if isrecord:
            self.record()

    def record(self):
        print("recoding")

class smartphone(phone):
    def call(self):
        print("sm")
        #super 调用父类的方法
        super().call("yes")

ph = smartphone()
ph.call()

